package actions;

import java.util.ArrayList;
import java.util.List;

import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import entities.*;
import controller.DoctorDAORemote;
import controller.EmployeeDAORemote;

public class DoctorAction extends Action {

	public DoctorDAORemote lookup() {
		DoctorDAORemote remote1 = null;
		try {
			InitialContext ctx = new InitialContext();
			remote1 = (DoctorDAORemote) ctx
					.lookup("java:global/GoodHealth/GoodHealth-ejb/DoctorDAO!controller.DoctorDAORemote");
			System.out.print(remote1);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return remote1;

	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub

		String act = request.getParameter("act");

		List<ExamineDetail> list = new ArrayList<ExamineDetail>();

		DoctorDAORemote remote = lookup();

		if (act != null) {
			if (act.equals("noneexamine")) {
				list = remote.listNoneExam();
			} else if (act.equals("examineed")) {
				list = remote.listExamed();
			}
		}
		else {
			list = remote.listNoneExam();
		}

		request.setAttribute("listExam", list);

		return mapping.findForward("home");
	}

}
